package ase.eleitweg.common;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * This Class represents the possible branching from a node in the workflow.
 * 
 * @author degi
 */
public class Conditions implements java.io.Serializable{

	private static final long serialVersionUID = 100L;
	
	private Node homeNode;
	private String titel;
	private List<Edge> conditions;
	
	public Conditions(Node homeNode, String titel){
		super();
		this.titel = titel;
		this.homeNode = homeNode;
		this.conditions = new LinkedList<Edge>();
	}
	
	public Conditions(){
		super();
		this.titel = "";
		this.homeNode = null;
		this.conditions = new LinkedList<Edge>();
	}
	
	public void setTitel(String titel){
		this.titel = titel;
	}
	
	public String getTitel(){
		return titel;
	}
	
	public void addEdge(Edge edge){
		conditions.add(edge);
	}
	
	public boolean removeEdge(Edge edge){
//		return conditions.remove(edge);
		
		boolean found=false;
		int x = -1;
		
		for(int i=0;i<conditions.size();i++){
			Edge tmpEdge = conditions.get(i);
			if(tmpEdge.isSimilar(edge)){
				x=i;
				found=true;
				break;
			}
		}
		
		if(found){
			removeEdge(x);
			return found;
		}
		else{
			return found;
		}
	}
	
	public void removeEdge(int index){
		conditions.remove(index);
	}
	
	public Iterator<Edge> getEdgesIterator(){
		return conditions.iterator();
	}
	
	public List<Edge> getEdges() {
		return conditions;
	}
	
	public int getEdgeCount(){
		return conditions.size();
	}
	
	public Edge getEdge(int index){
		return conditions.get(index);
	}
	
	public Node getHomeNode(){
		return homeNode;
	}
	
	public void setHomeNode(Node homeNode){
		this.homeNode = homeNode;
	}
}
